<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column fixed prop="orderBy" label="序号" width="60">
      </el-table-column>
      <el-table-column prop="name" label="名称"></el-table-column>
      <!-- <el-table-column prop="createName" label="创建人"> </el-table-column> -->
      <el-table-column prop="createTime" label="创建时间"> </el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="primary" size="mini" @click="handleEdit(row)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import {
  sysCourseSubTypeQuery,
  sysCourseSubTypeDelete,
} from "@/api/admin/courseLibrary/sysCourseSubType.js";
import Bus from "@/utils/bus.js";
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        type: this.$route.meta.type,
      },
      tableData: [],
      pageObj: {},
    };
  },
  mounted() {
    this.getList();
    Bus.$on("refreshCourseClassifyList", (v) => {
      if (v) {
        Object.assign(this.listQuery, v);
      }
      this.getList();
    });
  },
  beforeDestroy() {
    Bus.$off("refreshCourseClassifyList");
  },
  methods: {
    getList() {
      sysCourseSubTypeQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data;
        this.pageObj = res.data;
      });
    },
    //编辑
    handleEdit(row) {
      Bus.$emit("showDialogCourseClassifyAdd", row);
    },
    //删除确认
    handleDelete(row) {
      this.$confirm("确定要删除吗?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.delete(row);
        })
        .catch(() => {});
    },
    //删除
    delete(row) {
      sysCourseSubTypeDelete(row.id).then((res) => {
        this.getList();
        this.$message({
          message: "操作成功",
          type: "success",
        });
      });
    },
  },
};
</script>